﻿Imports TodoMicroSolutionPackV1.productos.dal.dto
Imports NHibernate
Imports TodoMicroSolutionPackV1.dal.dao
Public Class frmProductoSelect
    Private producto As producto
    Private productosList As IList
    Private _session As ISession
    Private DAOFactory As NHibernatedaofactory

    Protected ReadOnly Property Session As ISession
        Get
            If _session Is Nothing Then
                _session = NhibernateSessionFactory.getSession
            End If
            Return _session
        End Get
    End Property
    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        productosList = DAOFactory.getProductoDAO.buscarProductos(0, txtCodigo.Text, txtDescripcion.Text)
        dataGrid.DataSource = productosList
    End Sub
    Public Function getProducto(ByRef session As ISession) As producto
        _session = session
        Me.ShowDialog()
        Return Me.producto
    End Function

    Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
        producto = productosList.Item(dataGrid.CurrentRow.Index)
        Me.Dispose()
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        producto = Nothing
        Me.Dispose()
    End Sub

    Private Sub frmProductoSelect_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.Dispose()
    End Sub

    Private Sub frmProductoSelect_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        If e.KeyCode = Keys.Return Then
            btnBuscar.PerformClick()
        End If
    End Sub

    Private Sub frmProductoSelect_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DAOFactory = New NhibernateDAOFactory(Session)
        Me.KeyPreview = True
    End Sub


End Class